{% extends 'myadmin/base.html' %}

{% block title %}
<title>Book-Shop-会员列表</title>
{% endblock %}

{% block con %}
<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 会员管理
            </div>
        </div>
    </div>
</div>

<div class="row-content am-cf">
    <div class="row  am-cf">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">会员列表</div>
                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a href="{% url 'myadmin_users_add' %}"
                                       class="am-btn am-btn-default am-btn-success"><span
                                            class="am-icon-plus"></span> 新增
                                    </a>
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span
                                            class="am-icon-save"></span> 保存
                                    </button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span
                                            class="am-icon-archive"></span> 审核
                                    </button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span
                                            class="am-icon-trash-o"></span> 删除
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <form action="">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select name="selecttype" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                                <option value="all" {% if request.GET.selecttype == 'all' %} selected {% endif %}>所有类别</option>
                                <option value="phone" {% if request.GET.selecttype == 'phone' %} selected {% endif %}>手机号</option>
                                <option value="nickname" {% if request.GET.selecttype == 'nickname' %} selected {% endif %}>昵称</option>
                                <option value="sex" {% if request.GET.selecttype == 'sex' %} selected {% endif %}>性别</option>
                                <option value="usertype" {% if request.GET.selecttype == 'usertype' %} selected {% endif %}>身份</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input type="text" value="{{ request.GET.keywords }}" name="keywords" class="am-form-field ">
                            <span class="am-input-group-btn">
                                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" ></button>
                            </span>
                        </div>
                    </div>
                    </form>

                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>id</th>
                                    <th>头像</th>
                                    <th>手机号</th>
                                    <th>昵称</th>
                                    <th>性别</th>
                                    <th>身份</th>
                                    <th>注册时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for i in data %}
                                <tr class="gradeX">
                                    <td class="am-text-middle">{{ i.id }}</td>
                                    <td><img src="{{ i.face }}" class="tpl-table-line-img" alt=""></td>
                                    <td class="am-text-middle">{{ i.phone }}</td>
                                    <td class="am-text-middle">{{ i.nickname|default:'未填写' }}</td>
                                    <td class="am-text-middle">{% if i.sex == '0' %}女{% elif i.sex == '1' %}男{% else %}未知{% endif %}</td>
                                    <td class="am-text-middle">
                                        {% if i.usertype == '0' %}
                                            狼人
                                        {% elif i.usertype == '1' %}
                                            预言家
                                        {% elif i.usertype == '2' %}
                                            平民
                                        {% endif %}
                                    </td>
                                    <td class="am-text-middle">{{ i.registerdate|date:'Y-m-d H:i:s' }}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="javascript:;">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="javascript:;" class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}
                            <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">

                                <li>总页数:{{ data.paginator.num_pages }}</li>
                                <li>总条数:{{ data.paginator.count }}</li>

                                {% load pagetag %}
                                <!-- 使用自定义分页优化标签 -->
                                {% showpage data.paginator.num_pages request %}

                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // alert($);
    // 给删除按钮绑定一个单击事件
    $('.tpl-table-black-operation-del').click(function(){
        // 获取当前的数据id this是a链接
        id = $(this).parents('tr').find('td:first').text()
        a = $(this)
        // alert(id)
        // 发送ajax请求到后台 进行数据的删除
        // 大括号里面是模板引擎语法,先解析成字符串返回到浏览器中,才执行外面的,可以是单引号
        $.get('{% url "myadmin_users_delete" %}',{'id':id},function (data) {
            // 判断是否成功
            if(data['code'] == 0){
                // 删除当前的这一行数据 this是XMLHttpRequest,ajax对象
                // $(this).parents('tr').remove()
                // console.log($(this))
                a.parents('tr').remove()
            }
            alert(data['msg'])
        },'json')
    })
</script>
{% endblock %}

